FUNCTION ZFIFM_VIM_DETERM_PROC_153 .
*"----------------------------------------------------------------------
*"*"本地接口：
*"  TABLES
*"      INDEX_ITEM TYPE  /OPT/CIDH_1ITEM_T
*"  CHANGING
*"     REFERENCE(INDEX_DATA) TYPE  /OPT/VIM_1HEAD OPTIONAL
*"  EXCEPTIONS
*"      CHECK_FAILED
*"----------------------------------------------------------------------
  DATA: L_LIFNR  LIKE /OPT/VIM_1HEAD-LIFNR,
        LV_VALUE TYPE /PTGWFI/VALUE.                        "VIMI-8960
***>>>Begin of Changes 560/2
***Types
  TYPES  : BEGIN OF TY_ITEM,
             DOCID  TYPE /OPT/VIM_1ITEM-DOCID,
             ITEMID TYPE /OPT/VIM_1ITEM-ITEMID,
             EBELN  TYPE /OPT/VIM_1ITEM-EBELN,
             EBELP  TYPE /OPT/VIM_1ITEM-EBELP,              "VIMI-13235
           END OF TY_ITEM.
  TYPES : BEGIN OF TY_LIFNR,
            EBELN TYPE EKKO-EBELN,
            LIFNR TYPE EKKO-LIFNR,
          END OF TY_LIFNR.
***DATA delcariton for item validation
  DATA : LT_ITEM  TYPE STANDARD TABLE OF TY_ITEM,
         LT_LIFNR TYPE STANDARD TABLE OF TY_LIFNR.
***Worke area for item Validation
  DATA : WA_ITEM  TYPE TY_ITEM,
         WA_LIFNR TYPE TY_LIFNR.
*---begin of VIMI 5.2 sp4
  DATA: RC       TYPE SYST-SUBRC,
        LV_EBELN TYPE /OPT/VIM_1HEAD-EBELN,
*Begin of change VIMI-7262 7.0
*        po_list  TYPE /opt/vim_1head-po_list.
        LT_LIST  TYPE TABLE OF /OPT/VIM_1PO_DN,
        LS_LIST  TYPE /OPT/VIM_1PO_DN.
*End of change VIMI-7262 7.0
  TYPES : BEGIN OF TY_EBELN,
            EBELN TYPE EKKO-EBELN,
          END OF TY_EBELN.
  DATA  : TB_EBELN TYPE STANDARD TABLE OF TY_EBELN,
          TW_EBELN TYPE TY_EBELN.
*---End of   VIMi 5.2 sp4

* Start insert VIMI-13235 AKOESTLI
  DATA: LV_KNUMV  TYPE KNUMV,
        LV_LIFNR2 TYPE LIFNR.
* End insert VIMI-13235

  " Add by roc.wang 海关发票不做该检查
  SELECT COUNT(*)
    FROM ZFIT078_HEAD
   WHERE ZFPHM = INDEX_DATA-LXBLNR
     AND INVOICE_LINE LIKE '%17%'.
  IF SY-SUBRC = 0. "海关缴款书跳过检查
    RETURN.
  ENDIF.

  "运费发票跳过检查
  LOOP AT INDEX_ITEM INTO DATA(LS_INDEX_ITEM) WHERE COND_TYPE CS 'ZF'.
    EXIT.
  ENDLOOP.
  IF SY-SUBRC = 0.
    RETURN.
  ENDIF.

  " End add
*-----------------------------------------------------------------------
* Check if the Process type is applicable.
*-----------------------------------------------------------------------
***  DATA: ls_invtype TYPE /opt/vim_t100-inv_type,
***        ls_proc TYPE /opt/process_type.
**** Get the country and Invoice Type from the Doc Type
***  SELECT SINGLE inv_type
***  FROM   /opt/vim_t100
***  INTO   ls_invtype
***  WHERE  doctype EQ index_data-doctype.
***  IF sy-subrc EQ 0.
***    CASE ls_invtype.
***      WHEN 'NPO'.
***        ls_proc = ''.
***      WHEN 'LIV'.
***        ls_proc = '153'.
***    ENDCASE.
***
***  ELSE.
***    EXIT.
***  ENDIF.
***
***  CALL FUNCTION '/OPT/VIM_CHECK_PROCESS_TYPE'
***    EXPORTING
***      process_type   = ls_proc
***      index_data     = index_data
***    EXCEPTIONS
***      not_applicable = 1
***      OTHERS         = 2.
***  IF sy-subrc <> 0.
***    EXIT.
***  ENDIF.
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
*Begin of VIMI-8960 - cnicklas
  CALL FUNCTION '/OPT/VIM_READ_CONSTANT'
    EXPORTING
      PROD_CODE   = '005'
      PARAM_NAME  = 'FAIL_PO_HEADER_SET'
    IMPORTING
      PARAM_VALUE = LV_VALUE
    EXCEPTIONS
      NOT_FOUND   = 1
      OTHERS      = 2.
*End of VIMI-8960 - cnicklas

  SELECT  DOCID
          ITEMID
          EBELN
          EBELP                                             "VIMI-13235
          FROM  /OPT/VIM_1ITEM
                INTO  TABLE LT_ITEM
                WHERE DOCID = INDEX_DATA-DOCID.
  IF NOT  LT_ITEM[]  IS INITIAL.
    SELECT EBELN
           LIFNR INTO TABLE LT_LIFNR
                 FROM EKKO
                 FOR ALL ENTRIES IN LT_ITEM
                 WHERE EBELN = LT_ITEM-EBELN.

  ENDIF.
*>>>>Begin of VIMI 5.2 SP4

*---fetch all the PO docs from the PO List
*Begin of change VIMI-7262 7.0
*  SELECT SINGLE ebeln
*                po_list INTO (lv_ebeln , po_list)
*                        FROM /opt/vim_1head
*                        WHERE docid = index_data-docid.
  SELECT SINGLE EBELN INTO LV_EBELN
                        FROM /OPT/VIM_1HEAD
                        WHERE DOCID = INDEX_DATA-DOCID.
  SELECT * INTO TABLE LT_LIST FROM /OPT/VIM_1PO_DN
                              WHERE DOCID = INDEX_DATA-DOCID
                              AND   EBELN NE ''.
  LOOP AT LT_LIST INTO LS_LIST.
    APPEND LS_LIST-EBELN TO TB_EBELN.
  ENDLOOP.
***To Collect PO Numbers from po_list
*  IF NOT po_list IS INITIAL.
*    SPLIT po_list AT ',' INTO TABLE tb_ebeln.
*End of change VIMI-7262 7.0
  LOOP AT TB_EBELN INTO TW_EBELN.
*-- start SP6
*      unpack tw_ebeln-ebeln to tw_ebeln-ebeln.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = TW_EBELN-EBELN
      IMPORTING
        OUTPUT = TW_EBELN-EBELN.
*-- End SP6
* Start change VIMI-13235
*    SELECT SINGLE lifnr INTO l_lifnr FROM ekko WHERE
*                             ebeln = tw_ebeln-ebeln.
    SELECT SINGLE LIFNR KNUMV INTO (L_LIFNR, LV_KNUMV) FROM EKKO WHERE
                             EBELN = TW_EBELN-EBELN.

* End change VIMI-13235
    IF SY-SUBRC = 0.
      IF INDEX_DATA-LIFNR NE L_LIFNR.
        PERFORM VENDOR_PARTNERFUNCTION_CHECK USING TW_EBELN-EBELN
                                                   INDEX_DATA-BUKRS
                                                   INDEX_DATA-LIFNR
                                             CHANGING RC.
        IF RC NE 0.
* Start insert VIMI-13235 AKOESTLI - freight vendor?
          IF NOT LV_KNUMV = ' '.
            PERFORM FREIGHT_VENDOR_CHECK
                         USING
                            LV_KNUMV
                            INDEX_DATA-LIFNR
                         CHANGING
                            RC.
          ENDIF.
          IF RC NE 0.
* End insert VIMI-13235

*Begin of VIMI-8960 - cnicklas
            IF NOT LV_VALUE IS INITIAL.
              INDEX_DATA-EBELN = TW_EBELN-EBELN.
            ENDIF.

*End of VIMI-8960 - cnicklas
            RAISE CHECK_FAILED.
* Start insert VIMI-13235
          ENDIF.
* End insert VIMI-13235

        ENDIF.                                 "VIMI 5.2 SP4
      ENDIF.
    ELSE.
      RAISE CHECK_FAILED.
    ENDIF.
  ENDLOOP.
  CLEAR L_LIFNR.

*>>>>End   of VIMI 5.2 SP4

***>>>End of Changes 560/2

  IF NOT INDEX_DATA-EBELN IS INITIAL.
* Start change VIMI-13235
*    SELECT SINGLE lifnr INTO l_lifnr FROM ekko WHERE
*                             ebeln = tw_ebeln-ebeln.
    SELECT SINGLE LIFNR KNUMV INTO (L_LIFNR, LV_KNUMV) FROM EKKO WHERE
                             EBELN = INDEX_DATA-EBELN.
* End change VIMI-13235
    IF SY-SUBRC = 0.
      IF INDEX_DATA-LIFNR NE L_LIFNR.
*--Begin of VIM 5.2 SP4
        CLEAR RC.
        PERFORM VENDOR_PARTNERFUNCTION_CHECK USING INDEX_DATA-EBELN
                                                   INDEX_DATA-BUKRS
                                                   INDEX_DATA-LIFNR
                                             CHANGING RC.
        IF RC NE 0.
*--End   of VIM 5.2 SP4
* Start insert VIMI-13235 AKOESTLI - freight vendor
          IF NOT LV_KNUMV = ' '.
            PERFORM FREIGHT_VENDOR_CHECK
                         USING
                            LV_KNUMV
                            INDEX_DATA-LIFNR
                         CHANGING
                            RC.
          ENDIF.
          IF RC NE 0.
* End insert VIMI-13235
            RAISE CHECK_FAILED.
* Start insert VIMI-13235
          ENDIF.
* End insert VIMI-13235
        ENDIF.                                 "VIMI 5.2 SP4
      ENDIF.
    ELSE.
      RAISE CHECK_FAILED.
    ENDIF.
  ENDIF.
***>>>Begin of Changes 560/2
  CLEAR : WA_ITEM.
  LOOP AT LT_ITEM INTO WA_ITEM.
    CLEAR WA_LIFNR.
*   Begin of VIMI-16590/STAMADA
    SELECT SINGLE KNUMV INTO LV_KNUMV FROM EKKO WHERE
                             EBELN = WA_ITEM-EBELN.
*   End of VIMI-16590/STAMADA
* Start Insert VIMI-7914  AKOESTLI additional cost
    IF WA_ITEM-EBELN <> ' '.
* End Insert VIMI-7914
      READ TABLE LT_LIFNR INTO WA_LIFNR WITH KEY EBELN = WA_ITEM-EBELN .
      IF SY-SUBRC EQ 0.
        IF INDEX_DATA-LIFNR NE WA_LIFNR-LIFNR.
*--Begin of VIM 5.2 SP4
          CLEAR RC.
          PERFORM VENDOR_PARTNERFUNCTION_CHECK USING WA_ITEM-EBELN
                                                     INDEX_DATA-BUKRS
                                                     INDEX_DATA-LIFNR
                                               CHANGING RC.
          IF RC NE 0.
*--End   of VIM 5.2 SP4

* Start insert VIMI-13235 AKOESTLI
            PERFORM FREIGHT_VENDOR_ITEM_CHECK
                        USING
                           LV_KNUMV
                           INDEX_DATA-LIFNR
                           WA_ITEM-EBELP
                        CHANGING
                           RC.
            IF RC NE 0.
* End insert VIMI-13235

*Begin of VIMI-8960 - cnicklas
              IF NOT LV_VALUE IS INITIAL.
                INDEX_DATA-EBELN = WA_ITEM-EBELN.
              ENDIF.
*End of VIMI-8960 - cnicklas
              RAISE CHECK_FAILED.
* Start insert VIMI-13235 AKOESTLI
            ENDIF.
* End insert VIMI-13235
          ENDIF.                                 "VIMI 5.2 SP4
        ENDIF.
      ELSE.
        RAISE CHECK_FAILED.
      ENDIF.
* Start Insert VIMI-7914  AKOESTLI  additional cost
    ENDIF.
* End Insert VIMI-7914

  ENDLOOP.
***>>>End of Changes 560/2

ENDFUNCTION.
*&---------------------------------------------------------------------*
*&      Form  vendor_partnerfunction_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LIFNR    text
*      -->p_BUKRS    text
*      -->P_RC       text
*----------------------------------------------------------------------*
FORM VENDOR_PARTNERFUNCTION_CHECK USING P_EBELN TYPE EBELN
                                        P_BUKRS TYPE BUKRS
                                        P_LIFNR TYPE LIFNR
                                  CHANGING P_RC.

  CONSTANTS:L_COMM TYPE C VALUE ','.
  RANGES:WS_LIF FOR WYT3-PARVW OCCURS 0,
         WS_BLCK FOR LFB1-ZAHLS OCCURS 0.
  DATA:L_VALUE TYPE /PTGWFI/VALUE,
       L_EKKO  TYPE EKKO.
  TYPES:BEGIN OF WA_TAB1,
          PARVW TYPE PARVW,
        END OF WA_TAB1.
  TYPES:BEGIN OF WA_LIFN1,
*       lifnr type lifnr,
          LIFN2 TYPE WYT3-LIFN2,
        END OF WA_LIFN1.
  TYPES:BEGIN OF WA_LIFN2,
          LIFNR TYPE LIFNR,
        END OF WA_LIFN2.
  TYPES:BEGIN OF WA_BLCK,
          ZAHLS TYPE LFB1-ZAHLS,
        END OF WA_BLCK.

  DATA:IT_TAB  TYPE TABLE OF WA_TAB1,
       IT_LFB1 TYPE TABLE OF WA_LIFN2,
       IT_LIFN TYPE TABLE OF WA_LIFN1,
       WA_TAB  LIKE LINE OF  IT_TAB,
       WA_LIFN LIKE LINE OF IT_LIFN,
       WA_LFA1 LIKE LINE OF IT_LFB1,
       IT_BLCK TYPE TABLE OF WA_BLCK,
       LW_BLCK LIKE LINE OF IT_BLCK.
* Start of INS VIMI-19844
  DATA: LV_BSTYP  TYPE EBSTYP,
        LV_BSART  TYPE ESART,
        LV_LIFRE  TYPE LIFRE,
        LV_PARGR  TYPE PARGR,
        WA_EKPA   TYPE EKPA,
        WA_EK08BN TYPE EK08BN,
        LT_EKPA   TYPE TABLE OF EKPA,
        LT_EK08BN TYPE TABLE OF EK08BN.
* End of INS VIMI-19844
  CLEAR P_RC.
*--Get the configured the Vendor Partner functions.
  CALL FUNCTION '/OPT/VIM_READ_CONSTANT'
    EXPORTING
      PROD_CODE   = '005'
      PARAM_NAME  = 'EXIT_VEND_PARTN_FUNC'
    IMPORTING
      PARAM_VALUE = L_VALUE
    EXCEPTIONS
      NOT_FOUND   = 1
      OTHERS      = 2.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    P_RC = 4.
  ELSE.
    IF L_VALUE IS INITIAL.
      P_RC = 4.
      EXIT.
    ENDIF.
    SELECT SINGLE * FROM EKKO INTO L_EKKO WHERE EBELN = P_EBELN.
    IF SY-SUBRC EQ 0.
      SPLIT L_VALUE AT L_COMM INTO TABLE IT_TAB.


      LOOP AT IT_TAB INTO WA_TAB.
        MOVE: 'I' TO WS_LIF-SIGN,
              'EQ' TO WS_LIF-OPTION,
              WA_TAB-PARVW TO WS_LIF-LOW.
*Commented by bkalpana -VIMI-5777
*        CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
*          EXPORTING
*            input  = ws_lif-low
*          IMPORTING
*            output = ws_lif-low.
*Commented by bkalpana -VIMI-5777
        APPEND WS_LIF.
        CLEAR WS_LIF.
      ENDLOOP.



*---Get all the Partner Functions on the PO
      SELECT LIFN2 FROM EKPA INTO TABLE IT_LIFN
                           WHERE EBELN = P_EBELN
                           AND PARVW IN WS_LIF.
      IF SY-SUBRC EQ 0.
        READ TABLE IT_LIFN INTO WA_LIFN WITH KEY LIFN2 = P_LIFNR.
        IF SY-SUBRC EQ 0.
*          p_rc = sy-subrc.                   " VIMI-34756
*        else.
*          p_rc = sy-subrc.
*         endif.
*Begin of changes VIMI-34756
        ENDIF.
      ENDIF.
      P_RC = SY-SUBRC.
*End of changes VIMI-34756
*---Get all the Vendor ref partner functions
      IF P_RC <> 0.                              " VIMI-34756
        CLEAR IT_LIFN.
        SELECT
*           lifnr
            LIFN2 FROM WYT3 INTO TABLE IT_LIFN
                            WHERE LIFNR = L_EKKO-LIFNR
                             AND  EKORG = L_EKKO-EKORG
                             AND  PARVW IN WS_LIF.
*      endif.
*      endif.
        IF NOT IT_LIFN IS INITIAL.
*--- Consider only those blocks which required
*--- Get the blocks from Z Constant

*--Get the configured Vendor Partner blocks
*        clear l_value.
*        call function '/OPT/VIM_READ_CONSTANT'
*          exporting
*            prod_code   = '005'
*            param_name  = 'GET_VEND_PAYM_BLOCK'
*          importing
*            param_value = l_value
*          exceptions
*            not_found   = 1
*            others      = 2.
*        if sy-subrc <> 0.
*        else.
*          if not l_value is initial.
*            split l_value at l_comm into table it_blck.
*            loop at it_blck into lw_blck.
*              move: 'E' to ws_blck-sign,
*                          'EQ' to ws_blck-option,
*                          lw_blck-zahls  to ws_blck-low.
*              append ws_blck.
*              clear ws_blck.
*
*            endloop.
**        endif.
**---Check blocks on Vendor Partner functions
*            select lifnr from lfb1 into table it_lfb1
*                             for all entries in it_lifn
**                           where lifnr = it_lifn-lifnr
*                                where lifnr = it_lifn-lifn2
*                                and   bukrs = p_bukrs
*                                and   zahls  in ws_blck.
**        if sy-subrc eq 0.
**          loop at it_lfa1 into wa_lfa1.
***---if Vendor match then it is blocked then delete from the list
**            read table it_lifn into wa_lifn with key lifnr = wa_lfa1-lifnr.
**            if sy-subrc eq 0.
**              delete it_lifn where lifnr = wa_lfa1-lifnr.
**            endif.
**          endloop.
**        endif.
*
          READ TABLE IT_LIFN INTO WA_LIFN WITH KEY LIFN2 = P_LIFNR.
*            read table it_lfb1 into wa_lifn with key lifnr = p_lifnr.
          IF SY-SUBRC NE 0.
            P_RC = 4.
          ELSE.
            P_RC = 0.
          ENDIF.
        ELSE.
          P_RC = 4.
        ENDIF.
      ENDIF.
* Begin of VIMI-34756.
*      ELSE.
*        p_rc = 4 .
*      ENDIF.
* End of VIMI-34756.
    ENDIF.
  ENDIF.
* Start of INS VIMI-19844
  IF P_RC = 4.
    SELECT SINGLE BSTYP
                  BSART
                  LIFRE
             FROM EKKO
             INTO (LV_BSTYP,
                   LV_BSART,
                   LV_LIFRE)
            WHERE EBELN = P_EBELN.
    IF SY-SUBRC = 0.
      SELECT SINGLE PARGR
               FROM T161
               INTO LV_PARGR
              WHERE BSTYP = LV_BSTYP
                AND BSART = LV_BSART.
    ENDIF.
    CALL FUNCTION 'MM_READ_PARTNERS'
      EXPORTING
        APPLICATION = 'P'
        EBELN       = P_EBELN
        BSTYP       = LV_BSTYP
        PARGR       = LV_PARGR
      TABLES
        Y_EKPA      = LT_EKPA.
    READ TABLE LT_EKPA INTO WA_EKPA WITH KEY LIFN2 = P_LIFNR.
    IF SY-SUBRC = 0.
      CLEAR P_RC.
    ELSE.
      CALL FUNCTION 'ME_READ_COND_INVOICE'
        EXPORTING
          I_EBELN = P_EBELN
          I_LIFNR = ' '
        TABLES
          XEK08BN = LT_EK08BN.
      READ TABLE LT_EK08BN INTO WA_EK08BN WITH KEY LIFNR = P_LIFNR.
      IF SY-SUBRC = 0.
        CLEAR P_RC.
      ELSE.
        IF P_LIFNR = LV_LIFRE.
          CLEAR P_RC.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
* End of INS VIMI-19844
ENDFORM.                    "vendor_partnerfunction_check


*&---------------------------------------------------------------------*
*&      Form  freight_vendor_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_KNUMV    text
*      -->P_LIFNR    text
*      <--P_RC       text
*----------------------------------------------------------------------*
FORM FREIGHT_VENDOR_CHECK USING    P_KNUMV TYPE KNUMV
                                   P_LIFNR TYPE LIFNR
                          CHANGING P_RC.

  DATA: LV_KBETR TYPE KBETR,
        LV_EBELP TYPE EBELP.
  DATA: LS_SW_VERS  TYPE CVERS.                             "VIMI-16564
  DATA: LT_KONV     TYPE TABLE OF KONV.                     "VIMI-16564
  DATA: LS_KONV     TYPE KONV.                              "VIMI-16564
  DATA: LS_FM_NAME  TYPE TFDIR-FUNCNAME.                    "VIMI-16564

*Begin S4Hana Change - VIMI-16564
  CLEAR LS_SW_VERS.
  SELECT SINGLE * FROM CVERS INTO LS_SW_VERS WHERE COMPONENT = 'S4CORE'.
*End S4Hana Change - VIMI-16564

  IF LS_SW_VERS IS INITIAL. " VIMI-16564 not S4Hana system
    SELECT SINGLE KBETR FROM KONV INTO LV_KBETR
           WHERE KNUMV = P_KNUMV
           AND   KVSL1 = 'FRE'
           AND   LIFNR = P_LIFNR.

    IF SY-SUBRC = 0.
      P_RC = 0.
    ELSE.
      P_RC = 4.
    ENDIF.
*Begin S4Hana Change - VIMI-16564
  ELSE.
    P_RC = 4.
    REFRESH LT_KONV.
    LS_FM_NAME = '/OPT/VIM_S4_READ_KONV'.
    SELECT SINGLE FUNCNAME FROM   TFDIR
      INTO   LS_FM_NAME
      WHERE  FUNCNAME EQ LS_FM_NAME.
    IF SY-SUBRC = 0.
      CALL FUNCTION LS_FM_NAME
        EXPORTING
          IV_KNUMV                   = P_KNUMV
        CHANGING
*         ET_PRC_ELEM                =
          ET_PRC_ELEM_CLASSIC_FORMAT = LT_KONV.
    ENDIF.
    IF NOT LT_KONV[] IS INITIAL.
      READ TABLE LT_KONV INTO LS_KONV WITH KEY KNUMV = P_KNUMV
              KVSL1 = 'FRE'
              LIFNR = P_LIFNR.
      IF NOT LS_KONV IS INITIAL.
        CLEAR P_RC.
      ENDIF.
    ENDIF.
  ENDIF.
*End S4Hana Change - VIMI-16564
ENDFORM.                     "freight_vendor_check


*&---------------------------------------------------------------------*
*&      Form  freight_vendor_item_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_KNUMV    text
*      -->P_LIFNR    text
*      -->P_EBELP    text
*      <--P_RC       text
*----------------------------------------------------------------------*
FORM FREIGHT_VENDOR_ITEM_CHECK USING    P_KNUMV TYPE KNUMV
                                        P_LIFNR TYPE LIFNR
                                        P_EBELP
                          CHANGING P_RC.

  DATA: LV_KBETR TYPE KBETR,
        LV_EBELP TYPE EBELP.
  DATA: LS_SW_VERS  TYPE CVERS.                             "VIMI-16564
  DATA: LT_KONV     TYPE TABLE OF KONV.                     "VIMI-16564
  DATA: LS_KONV     TYPE KONV.                              "VIMI-16564
  DATA: LS_FM_NAME  TYPE TFDIR-FUNCNAME.                    "VIMI-16564

*Begin S4Hana Change - VIMI-16564
  CLEAR LS_SW_VERS.
  SELECT SINGLE * FROM CVERS INTO LS_SW_VERS WHERE COMPONENT = 'S4CORE'.
*End S4Hana Change - VIMI-16564

  IF LS_SW_VERS IS INITIAL. " VIMI-16564 not S4Hana system
    SELECT SINGLE KBETR FROM KONV INTO LV_KBETR
           WHERE KNUMV = P_KNUMV
           AND   KVSL1 = 'FRE'
           AND   LIFNR = P_LIFNR
           AND   KPOSN = P_EBELP.

    IF SY-SUBRC = 0.
      P_RC = 0.
    ELSE.
      P_RC = 4.
    ENDIF.
*Begin S4Hana Change - VIMI-16564
  ELSE.
    P_RC = 4.
    REFRESH LT_KONV.
    LS_FM_NAME = '/OPT/VIM_S4_READ_KONV'.
    SELECT SINGLE FUNCNAME FROM   TFDIR
      INTO   LS_FM_NAME
      WHERE  FUNCNAME EQ LS_FM_NAME.
    IF SY-SUBRC = 0.
      CALL FUNCTION LS_FM_NAME
        EXPORTING
          IV_KNUMV                   = P_KNUMV
        CHANGING
*         ET_PRC_ELEM                =
          ET_PRC_ELEM_CLASSIC_FORMAT = LT_KONV.
    ENDIF.
    IF NOT LT_KONV[] IS INITIAL.
      READ TABLE LT_KONV INTO LS_KONV WITH KEY KNUMV = P_KNUMV
              KVSL1 = 'FRE'
              LIFNR = P_LIFNR
              KPOSN = P_EBELP.
      IF NOT LS_KONV IS INITIAL.
        CLEAR P_RC.
      ENDIF.
    ENDIF.
  ENDIF.
*End S4Hana Change - VIMI-16564
ENDFORM.                     "freight_vendor_item_check
